<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../js/vue.js"></script>
  <style>
    * {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }

    body,
    html {
      height: 100vh;
    }

    ul {
      list-style: none;
    }

    ul li {
      padding: 10px 10px;
      border: 1px solid black;
    }

    ul li {
      margin-top: 10px;
    }

    ul li {
      cursor: pointer;
    }

    ul li:hover {
      background-color: hotpink;
      transition: all 3s ease;
    }

    .v-enter,
    .v-leave-to {
      opacity: 0;
      transform: translateY(80px);
    }

    .v-enter-active,
    .v-leave-active {
      transition: all 5s ease;
    }

    /* 元素离开时，设置动画.记住即可*/
    .v-move {
      transition: all 1s ease;
    }

    .v-leave-active {
      position: absolute;
      width: 100%;
    }
  </style>
</head>

<body>
  <!-- v-for设置动画，必须为每个元素设置 :key属性 -->
  <div id="app">
    <label for="txt">
      ID:<input id="txt" type="text" v-model="txt1">
    </label>
    <label for="inp">
      name:<input id="inp" type="text" v-model="txt2">
    </label>
    <input type="button" value="提交" @click="add">
    <ul>
      <transition-group>
        <li v-for="(items,index) in list" :key="items.id" @click="del(index)">
          {{items.id}} === {{items.name}}
        </li>
      </transition-group>
    </ul>
  </div>
</body>
<script>
  const vm = new Vue({
    el: "#app",
    data: {
      txt1: "",
      txt2: "",
      list: [{
        id: "1",
        name: "赵高"
      }, {
        id: "2",
        name: "严嵩"
      }, {
        id: "3",
        name: "魏忠贤"
      }, {
        id: "4",
        name: "和珅"
      }]
    },
    methods: {
      add() {
        this.list.push({
          id: this.txt1,
          name: this.txt2
        });
        this.txt1 = "";
        this.txt2 = "";
      },
      del(index) {
        console.log(index);
        this.list.splice(index, 1);
      }
    }
  });
</script>

</html>